package com.csl.jsonpreference.test

import com.csl.jsonpreference.bean.ConfigTYPE
import com.csl.jsonpreference.tag.Configurable
import com.google.gson.Gson
import org.json.JSONObject

/**
 * aqua car 设备端车辆配置.
 */
@Configurable(discribe = "小车底盘配置")
class AquaCarRemoteConfig  {

    companion object {
        fun createForJson(json: JSONObject): AquaCarRemoteConfig {
            var config: AquaCarRemoteConfig =
                Gson().fromJson(json.toString(), AquaCarRemoteConfig::class.java)
            config.carMode = CarMode.getCarModeForCode(json.optInt("carMode"))
            return config
        }
    }

    @Configurable(discribe = "底盘类型", index = 0)
    var carMode: CarMode = CarMode.CAR_NOMAL


    @Configurable(discribe = "左前马达", type = ConfigTYPE.OBJECT, index = 1)
    var motorLT: AquaCarMotorConfig = AquaCarMotorConfig()

    @Configurable(discribe = "右前马达", type = ConfigTYPE.OBJECT, index = 2)
    var motorRT: AquaCarMotorConfig = AquaCarMotorConfig()

    @Configurable(discribe = "左后马达", type = ConfigTYPE.OBJECT, index = 3)
    var motorLB: AquaCarMotorConfig = AquaCarMotorConfig()

    @Configurable(discribe = "右后马达", type = ConfigTYPE.OBJECT, index = 4)
    var motorRB: AquaCarMotorConfig = AquaCarMotorConfig()


    override fun toString(): String {
        return "AquaCarConfig(carMode=$carMode, motorLT=$motorLT, motorRT=$motorRT, motorLB=$motorLB, motorRB=$motorRB)"
    }


//    @Configurable(discribe = "byte", type = ConfigTYPE.NUMBER, index = 0)
//    var carMode1: Byte = 0

//    @Configurable(discribe = "short", type = ConfigTYPE.NUMBER, index = 1)
//    var carMode2: Short = 0
//
//    @Configurable(discribe = "int", type = ConfigTYPE.NUMBER, index = 2)
//    var carMode5: Int = 0
//
//    @Configurable(discribe = "string", type = ConfigTYPE.TXT, index = 3)
//    var carMode3: String = ""
//
//    @Configurable(discribe = "long", type = ConfigTYPE.NUMBER, index = 4)
//    var carMode4: Long = 0
//
//    @Configurable(discribe = "boolean", type = ConfigTYPE.BOOLEAN, index = 5)
//    var carMode6: Boolean = false
//
//    @Configurable(discribe = "四轮类型", type = ConfigTYPE.TXT, index = 6)
//    var carMode: String = ""
//
//    @Configurable(discribe = "四轮类型2", index = 7)
//    var carMode7: CarMode = CarMode.CAR_NOMAL
//    override fun toString(): String {
//        return "AquaCarConfig(carMode1=$carMode1, carMode2=$carMode2, carMode5=$carMode5, carMode3='$carMode3', carMode4=$carMode4, carMode6=$carMode6, carMode='$carMode', carMode7=$carMode7)"
//    }


}